package filter;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

public class RulesFilter {
	public static void main(String[] args){
		HashMap<String,ArrayList<String>> hm=new HashMap<String,ArrayList<String>>();
		FileReader fr=null;
		BufferedReader br=null;
		FileOutputStream fos=null;
		ObjectOutputStream oos=null;
		String line = null;
		String[] lines = null;
		ArrayList<String> all=new ArrayList<String>();
		try{
			fr=new FileReader("data/rules.txt");
			br=new BufferedReader(fr);
			while((line=br.readLine())!=null){
				ArrayList<String> catalog=new ArrayList<String>();
				lines=line.split(",");
				if(lines!=null&&lines.length>1){
					hm.put(lines[0].toLowerCase().trim(),catalog);
					String temp = null;
					temp=lines[0].trim().toLowerCase();
					if(!all.contains(temp)){
						all.add(temp);
					}
					for(int i=1; i<lines.length; i++){
						temp=lines[i].trim().toLowerCase();
						catalog.add(temp);
						if(!all.contains(temp)){
							all.add(temp);
						}
					}
				}
			}
			hm.put("all",all);
			br.close();
			fr.close();
			fos=new FileOutputStream("Rules.obj");
			oos=new ObjectOutputStream(fos);
			oos.writeObject(hm);
			oos.close();
			fos.close();
		}
		catch(Exception e){
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
